<template>
  <uni-popup ref="popup" type="bottom" @mask-click="handleConfirm">
    <view class="flex-col bg-white content-wrap">
      <view class="flex-row align-center justify-between lineBottom10" style="padding: 20rpx">
        <text @click="handleReset">重置</text>
        <text @click="handleConfirm" class="text-blue">确定</text>
      </view>
	  <view class="lineBottom10 flex-col search-item">
	    <text>状态</text>
	    <view style="margin: 10rpx 0">
	      <uni-tag @click="statusClick(index,item)" :inverted="!item.check" :circle="true"
	               v-for="(item, index) in statusList" :text="item.label"
	               :key="item.value"
	               type="success"/>
	    </view>
	  </view>
		<view class="lineBottom10 flex-col search-item">
		  <text>车架号</text>
		  <view style="margin: 10rpx 0">
		    <uni-easyinput style="margin: 10rpx 0" type="text" v-model="ruleForm.vinNo"
		                   placeholder="请输入车架号"/>
		  </view>
		</view>
		<view class="lineBottom10 flex-col search-item">
		  <text>业务类型</text>
		   <uni-data-select
		        v-model="ruleForm.businessScopeCode"
		        :localdata="range"
		        @change="change"
		      ></uni-data-select>
		</view>
		<view class="lineBottom10 flex-col search-item">
		  <text>来源</text>
		  <view class="flex-row bottom10 flex-wrap">
					<zxz-uni-data-select
					  v-model="ruleForm.purchaseSource"
					  dataKey="label"
					  dataValue="value"
					  :localdata="dict.type.in_storage_source" style='width:100%'></zxz-uni-data-select>
		  </view>
		</view>
		<view class="lineBottom10 flex-col search-item">
		  <text>车辆归属</text>
		  <view style="margin: 10rpx 0">
		    <uni-easyinput style="margin: 10rpx 0" type="text" v-model="ruleForm.ascription"
		                   placeholder="请输入车辆归属"/>
		  </view>
		</view>
     

     

      <view class="lineBottom10 flex-col search-item">
        <text>客户名称</text>
        <view style="margin: 10rpx 0">
          <uni-easyinput style="margin: 10rpx 0" type="text" v-model="ruleForm.customerName"
                         placeholder="请输入客户名称"/>
        </view>
      </view>




    </view>
  </uni-popup>
</template>

<script>

export default {
  name: 'conditionSearch',//弹框搜索
  dicts: ['in_storage_source'],
  props: {
    value: {
      type: Object,
      default: {}
    },
	type:{
		   type:String,
		   default:'in',
	}
  },
  computed: {
    ruleForm: {
      get() {
        let that = this;
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key);
          },
          set(target, key, value) {
            that.$emit("input", {...target, [key]: value});
            return true;
          },
        });
        return proxy;
      },
    },
  },
  watch: {
	  type:{
		  deep:true,
		  handler(val){
			  if(val=='in'){
				  this.statusList = [
					{value:'1',label:'待入库',check: false},
					{value:'2',label:'已入库',check: false},
				  ]
			  }else{
				  this.statusList = [
						{value:'1',label:'待出库',check: false},
						{value:'2',label:'已出库',check: false},
				  ]
			  }
		  },
		  immediate:true
	  },
	  statusList:{
		  deep:true,
		  handler(val){
			  this.statusList = val
		  }
	  }
  },
  data() {
    return {
      param: {},
      range: [],
      linkageList: [],
	  range:[
		  {value:'0',text:'全部'},
		  {value:'1',text:'自营'},
		  {value:'2',text:'渠道'},
	  ],
	  purchaseSourceList:[],
	  statusList:[
		  {value:'1',label:'待入库',check: false},
		  {value:'2',label:'已入库',check: false},
	  ]
    };
  },
  created() {
	  
  },
  mounted() {
  },
  methods: {
	//打开弹框
	open() {
	  this.$refs.popup.open()
	},
    //确定
    handleConfirm() {
      this.$emit('confirm', this.ruleForm)
      this.$refs.popup.close()
    },

    //重置
    handleReset() {
      this.dict.type.in_storage_source.forEach(item => item.check = false)
      this.$emit('reset')
	  if(this.type=='in'){
		  this.statusList = [
			{value:'1',label:'待入库',check: false},
			{value:'2',label:'已入库',check: false},
		  ]
	  }else{
		  this.statusList = [
			{value:'1',label:'待出库',check: false},
			{value:'2',label:'已出库',check: false},
		  ]
	  }
	  // this.$refs.popup.close()
    },

    //状态
    statusClick(index, val) {
		this.statusList.forEach((item, i) => {
		  if (index === i) {
		    item.check = !item.check
		  } else {
		    item.check = false
		  }
		})
      this.$set(this.ruleForm, 'storageStatus', val.value)
      this.value.storageStatus = this.ruleForm.storageStatus = val.value
      this.$forceUpdate()
    },


    //业务类型
    change(val) {
      this.$set(this.ruleForm, 'businessScopeCode', val)
      this.value.businessScopeCode = this.ruleForm.businessScopeCode = val
    },
	// 来源
		
	purchaseSourcechange(val){
		this.$set(this.ruleForm,'purchaseSource',val)
		this.value.purchaseSource = this.ruleForm.purchaseSource = val
	}

  },
};
</script>

<style lang="scss" scoped>
.content-wrap {
  border-radius: 20rpx 20rpx 0 0
}

.search-item {
  padding: 0 20rpx 10rpx
}

uni-tag {
  margin: 20rpx 20rpx 10rpx 0
}

</style>



